package com.hd.controller;

import com.hd.controller.vo.Node;
import com.hd.service.PermissionService;
import com.hd.tools.Log;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by 1 on 2017/11/6.
 */
@RestController
@RequestMapping("/sys/permission")
public class PermissionController {

    private String msg;

    @Resource
    private PermissionService permissionService;

    @RequestMapping("/getTree")
    public List<Node> getTree(Integer roleId){
        List<Node> list = permissionService.searchNodes4Tree(roleId);
        return list;
    }

    @PostMapping("/grant")
    public String grant(Integer roleId,Integer[] menuIds){
        try{
            permissionService.grant(roleId,menuIds);
            msg = "预约成功!";
        }catch (Exception ex){
            msg = "预约失败!";
            Log.logger.error(msg,ex);
        }
        return msg;
    }

}
